const paths = require('./paths');
const { resolveApp } = require('./paths')
const HtmlWebpackPlugin = require('html-webpack-plugin');

const config = {
	// 入口
	entry: {
		index: './src/index.js',
	},
	module: {
		rules: [
			// 加载图片
			{
				test: /\.(png|svg|jpg|jpeg|gif)$/i,
				include: paths.appSrc,
				type: 'asset/resource',
			},
			// 加载字体
			{
				test: /.(woff|woff2|eot|ttf|otf)$/i,
				include: [
					 resolveApp('src'),
				 ],
				type: 'asset/resource',
			},
			// 加载CSS
			{
				test: /\.css$/,
				include: paths.appSrc,
				use: [
					// 将 JS 字符串生成为 style 节点
					'style-loader',
					// 将 CSS 转化成 CommonJS 模块
					'css-loader',
				],
			},
			// 加载sass
			{
        test: /.(scss|sass)$/,
        include: paths.appSrc,
        use: [
          // 将 JS 字符串生成为 style 节点
          'style-loader',
          // 将 CSS 转化成 CommonJS 模块
          'css-loader',
          // 将 Sass 编译成 CSS
          'sass-loader',
        ],
      },
		],
	},
	plugins: [
    // 生成html，自动引入所有bundle
    new HtmlWebpackPlugin({
      title: 'release_v0',
    }),
  ],
}

module.exports = config;